(function(window) {
	if (!window || !navigator) return;
	var u = navigator.userAgent;
	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

	var KeyboardUpEvent = document.createEvent('KeyboardEvent');
	KeyboardUpEvent.initEvent('KeyboardUp', true, true);

	var KeyboardDownEvent = document.createEvent('KeyboardEvent');
	KeyboardDownEvent.initEvent('KeyboardDown', true, true);

	if (isAndroid) {
		var originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
		window.onresize = function() {
			var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
			if (resizeHeight - 0 < originalHeight - 0) {
				document.dispatchEvent(KeyboardUpEvent);
			} else {
				document.dispatchEvent(KeyboardDownEvent);
			}
		};
	} else if (isiOS) {
		document.body.addEventListener('focusin', () => {
			document.dispatchEvent(KeyboardUpEvent);
		});
		document.body.addEventListener('focusout', () => {
			document.dispatchEvent(KeyboardDownEvent);
		});
	} else {
		throw '无法识别浏览器机型，请检查navigator.userAgent是否被重新定义过.';
	}
})(window);
